<!--
 * @Author: lichunyao licy529529@163.com
 * @Date: 2022-07-19 13:54:42
 * @LastEditors: lichunyao licy529529@163.com
 * @LastEditTime: 2022-07-26 09:43:49
 * @FilePath: \digital_workshop\_web\src\views\main\proplan\editForm.vue
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
-->
<template>
  <a-modal title="查看生产计划" width="80%" :visible="visible" :confirmLoading="confirmLoading" @cancel="handleCancel">
    <a-spin :spinning="confirmLoading">
      <a-form :form="form">
        <a-form-item v-show="false"><a-input v-decorator="['id']" /></a-form-item>
        <a-form-item label="单据编号" :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input
            readOnly
            placeholder="请输入单据编号"
            v-decorator="['code', { rules: [{ required: true, message: '请输入单据编号！' }] }]"
          />
        </a-form-item>
        <proplan-table-form-item
          :dataSource="workOrderList"
          :proList="list.proList"
          :plaNum="form.getFieldValue('plaNum') ? form.getFieldValue('plaNum') : null"
          :disabled="true"
          @add="
            ({ tableData }) => {
              workOrderList = tableData
            }
          "
          @del="
            ({ tableData }) => {
              workOrderList = tableData
            }
          "
        />
        <a-form-item label="备注" :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-textarea :rows="3" placeholder="请输入备注信息" v-decorator="['remarks']" :disabled="true" />
        </a-form-item>
      </a-form>
    </a-spin>
    <template slot="footer">
      <a-button @click="handleCancel">关闭</a-button>
    </template>
  </a-modal>
</template>

<script>
import proplanTableFormItem from './proplanTableFormItem.vue'
import { proList } from '@/api/modular/main/pro/proManage'
export default {
  components: { proplanTableFormItem },
  data() {
    return {
      labelCol: {
        xs: { span: 24 },
        sm: { span: 3 }
      },
      wrapperCol: {
        xs: { span: 24 },
        sm: { span: 20 }
      },
      labelCol_T: {
        xs: { span: 24 },
        sm: { span: 6 }
      },
      wrapperCol_T: {
        xs: { span: 24 },
        sm: { span: 16 }
      },
      visible: false,
      confirmLoading: false,
      form: this.$form.createForm(this),
      list: {
        // 产品
        proList: []
      },
      // 生产订单
      workOrderList: []
    }
  },
  provide() {
    return {
      getProList: this.getProList
    }
  },
  methods: {
    // 初始化方法
    async open(record) {
      this.visible = true
      this.workOrderList = record.workOrderList
      // 有问题？为解决list.proList传的是什么
      // proList().then((res) => {
      //   this.list.proList = res.data
      // })
      await this.getProList()
      setTimeout(() => {
        this.form.setFieldsValue({
          id: record.id,
          code: record.code,
          remarks: record.remarks
        })
      }, 100)
    },
    // 获取prolist表单
    async getProList() {
      this.list.proList = []
      var promise = proList().then((res) => {
        this.list.proList = res.data
      })
      await promise
      return this.list.proList
    },
    handleSubmit() {
      this.form.resetFields()
      this.visible = false
      this.$emit('ok')
    },
    handleCancel() {
      this.form.resetFields()
      this.visible = false
      this.$emit('ok')
    }
  }
}
</script>
